<?php
/**
 * Niushop商城系统 - 团队十年电商经验汇集巨献!
 * =========================================================
 * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: https://www.niushop.com
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
 * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
 * =========================================================
 */

namespace app\model\shop;


use app\model\BaseModel;
use app\model\goods\Goods;
use app\model\pay\Huifu;
use app\model\system\Config as ConfigModel;
use app\model\system\Group;
use app\model\web\WebSite as WebsiteModel;

/**
 * 店铺信息（无缓存）
 */
class Shop extends BaseModel
{

    /**
     * 添加店铺(注意入驻时长)
     * @param unknown $shop_data 店铺信息(注意是否自营)
     * @param unknown $cert_data 认证信息
     * @param unknown $user_info 用户信息
     */
    public function addShop($shop_data, $cert_data, $user_info,$type=0)
    {
        model('shop')->startTrans();
        try {
            //添加系统站
            $site_id = model("site")->add([ 'site_type' => 'shop' ]);
            $shop_data[ 'site_id' ] = $site_id;
            $shop_data[ 'expire_time' ] = 0;
            $shop_data[ 'shop_status' ] = 0;
            /*if ($shop_data[ 'is_own' ] == 1) {
                $shop_data[ 'expire_time' ] = 0;
            } else {
                $shop_data[ 'expire_time' ] = time() + 365 * 24 * 3600 * $shop_data[ 'year' ];
            }
            unset($shop_data[ 'year' ]);*/
            $shop_data[ 'username' ] = $user_info[ 'username' ];

            //关联前台会员检测
            $member_id = $shop_data[ 'member_id' ];
            $shop_type = $shop_data[ 'shop_type' ];
            if ($member_id != 0) {
                //检测是否有商家申请存在
                if ($type==0){
                    $shop_apply_count = model("shop_apply")->getCount([ [ 'member_id', '=', $member_id ],['shop_type','=',$shop_type] ]);
                    if ($shop_apply_count > 0) {
                        model("shop")->rollback();
                        return $this->error('', 'SHOP_APPLY_EXISTED');
                    }
                }

                //检测是否已被其他商家关联
                $shop_count = model('shop')->getCount([ [ 'member_id', '=', $member_id ] ,['shop_type','=',$shop_type]]);
                if ($shop_count > 0) {
                    model("shop")->rollback();
                    return $this->error('', 'MEMBER_SHOP_BIND_EXISTED');
                }
            }

            $shop_data[ 'create_time' ] = time();

            $cert_data[ 'site_id' ] = $site_id;
            //添加店铺认证信息
            $cert_id = model("shop_cert")->add($cert_data);

            //添加店铺
            $shop_data[ 'cert_id' ] = $cert_id;
            $res = model("shop")->add($shop_data);
            //添加系统用户组
            $group = new Group();
            $group_data = [
                'site_id' => $site_id,
                'app_module' => 'shop',
                'group_name' => '管理员组',
                'is_system' => 1,
                'create_time' => time()
            ];
            $group_id = $group->addGroup($group_data)[ 'data' ];
            // 添加店铺相册默认分组
            model("album")->add([ 'site_id' => $site_id, 'album_name' => "默认分组", 'update_time' => time(), 'is_default' => 1 ]);

            //用户检测
            if (empty($user_info[ 'username' ])) {
                model("shop")->rollback();
                return $this->error('', 'USER_NOT_EXIST');
            }
            $user_count = model("user")->getCount([ [ 'username', '=', $user_info[ 'username' ] ], [ 'app_module', '=', 'shop' ] ]);
            if ($user_count > 0) {
                model("shop")->rollback();
                return $this->error('', 'USERNAME_EXISTED');
            }

            //添加用户
            $data_user = [
                'app_module' => 'shop',
                'app_group' => $shop_data[ 'group_id' ],
                'is_admin' => 1,
                'group_id' => $group_id,
                'group_name' => '管理员组',
                'site_id' => $site_id
            ];
            $user_info = array_merge($data_user, $user_info);
            model("user")->add($user_info);
            //执行事件
            event("AddShop", [ 'site_id' => $site_id ]);

            model("shop")->commit();
            if ($type==0){
                return $this->success($res);
            } else {
                return $this->success($site_id);
            }
        } catch (\Exception $e) {
            model("shop")->rollback();
            return $this->error("", $e->getMessage());
        }
    }

    /**
     * 修改店铺(不能随意修改组)
     * @param array $data
     */
    public function editShop($data, $condition)
    {
        model('shop')->startTrans();
        try {
            $temp_data = $data;
            //查询过期时间有无更改
            $shop_info = $this->getShopInfo($condition);
            //$expire_time = $shop_info[ 'data' ][ 'expire_time' ];
            //过期关闭店铺
           /* if (!empty($data[ "expire_time" ])) {
                if ($data[ "expire_time" ] != $expire_time) {
                    //如果过期
                    if ($data[ "expire_time" ] - time() < 0) {
                        $data[ "shop_status" ] = 0;
                    }
                }
            }*/
            /*if (!empty($temp_data[ 'shop_status' ])) {
                if ($shop_info[ 'data' ][ 'shop_status' ] != $temp_data[ 'shop_status' ]) {
                    $data[ "shop_status" ] = $temp_data[ 'shop_status' ];
                }
            }*/
            //修改店铺信息
            //dump($data);die;
            $res = model('shop')->update($data, $condition);

            $check_condition = array_column($condition, 2, 0);
            $site_id = $check_condition[ "site_id" ];
            //订单关闭
            if (isset($data[ "shop_status" ]) && $data[ "shop_status" ] == 0) {
                $close_result = event("ShopClose", [ "site_id" => $site_id ], true);
                if (!empty($close_result) && $close_result[ "code" ] < 0) {
                    return $close_result;
                }
            }
            $group_id = $data[ 'group_id' ] ?? 0;
            if ($group_id > 0) {
                //修改用户权限
                $user_data = [
                    'app_group' => $data[ 'group_id' ]
                ];
                model('user')->update($user_data, [ [ 'site_id', '=', $site_id ] ]);
            }
            $website_id = $data['website_id'] ?? -1;
            if($website_id >= 0){
                $yuan_website_id = $shop_info['data']['website_id'] ?? 0;
                if($website_id != $yuan_website_id){
                    $goods_model = new Goods();
                    $goods_model->editWebsiteId($site_id,$website_id);
                }
            }
            model('shop')->commit();
            return $this->success($res);

        } catch (\Exception $e) {

            model('shop')->rollback();
            return $this->error('', $e->getMessage());
        }
    }

    /**
     * 获取店铺信息
     * @param array $condition
     * @param string $field
     */
    public function getShopInfo($condition, $field = '*')
    {

        $res = model('shop')->getInfo($condition, $field);

        if (isset($res[ 'shop_label' ]))$res[ 'shop_label' ] = json_decode($res[ 'shop_label' ]);

        return $this->success($res);
    }

    /**
     * 获取店铺详情
     * @param int $site_id
     */
    public function getShopDetail($site_id)
    {
        $res = [];
        $shop_info = model('shop')->getInfo([ [ 'site_id', '=', $site_id ] ], 'site_id,expire_time,site_name,username,website_id,cert_id,is_own,level_id,level_name,category_id,category_name,group_id,group_name,shop_status,logo,avatar,banner,seo_description,qq,ww,telephone,is_recommend,shop_desccredit,shop_servicecredit,shop_deliverycredit,workingtime,shop_baozh,shop_baozhopen,shop_baozhrmb,shop_qtian,shop_zhping,shop_erxiaoshi,shop_tuihuo,shop_shiyong,shop_shiti,shop_xiaoxie,shop_sales,shop_adv,sub_num,email');

        $res [ 'shop_info' ] = $shop_info;

//		客服配置信息

        return $this->success($res);
    }

    /**
     * 获取店铺列表
     * @param array $condition
     * @param string $field
     * @param string $order
     * @param string $limit
     */
    public function getShopList($condition = [], $field = '*', $order = '', $limit = null)
    {

        $list = model('shop')->getList($condition, $field, $order, '', '', '', $limit);
        return $this->success($list);
    }

    /**
     * 获取店铺列表(带认证信息)
     * @param array $condition
     * @param string $field
     * @param string $order
     * @param string $limit
     */
    public function getShopCertList($condition = [], $order = '', $limit = null)
    {
        $alias = 's';
        $join = [
            [
                'shop_cert sc',
                's.cert_id = sc.cert_id',
                'left'
            ]
        ];

        //店铺字段
        $shop_field = 's.site_id,s.expire_time,s.site_name,s.username,s.is_own,s.level_name,s.category_name,s.group_name,
            s.member_name,s.shop_status,s.close_info,s.start_time,s.end_time,s.seo_keywords,s.seo_description,s.qq,
            s.ww,s.telephone,s.is_recommend,s.shop_desccredit,s.shop_servicecredit,s.shop_deliverycredit,s.workingtime,
            s.shop_baozh,s.shop_baozhopen,s.shop_baozhrmb,s.shop_qtian,s.shop_zhping,s.shop_erxiaoshi,s.shop_tuihuo,s.shop_shiyong,
            s.shop_shiti,s.shop_xiaoxie,s.shop_free_time,s.shop_sales,s.account,s.work_week,s.full_address,s.sub_num,';

        //认证字段
        $cert_field = 'sc.cert_type,sc.company_name,sc.company_address,sc.contacts_name,sc.contacts_mobile,sc.contacts_card_no,
            sc.business_licence_number,sc.business_sphere,sc.taxpayer_id,sc.general_taxpayer,sc.tax_registration_certificate,
            sc.bank_account_name,sc.bank_account_number,sc.bank_name,sc.bank_address,sc.bank_code,sc.bank_type,sc.settlement_bank_account_name,
            sc.settlement_bank_account_number,sc.settlement_bank_name,sc.settlement_bank_address';

        $list = model('shop')->getList($condition, $shop_field . $cert_field, $order, $alias, $join);
        return $this->success($list);
    }

    /**
     * 获取店铺分页列表
     * @param array $condition
     * @param number $page
     * @param string $page_size
     * @param string $order
     * @param string $field
     */
    public function getShopPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
    {
        $list = model('shop')->rawPageList($condition, $field, $order, $page, $page_size);
        return $this->success($list);
    }

    /**
     * 添加店铺认证信息
     * @param $data
     * @param $condition
     * @return array
     */
    public function addShopCert($data)
    {
        $res = model('shop_cert')->add($data);
        return $this->success($res);
    }

    /**
     * 编辑店铺认证信息
     * @param $data
     * @param $condition
     * @return array
     * $type为1表示更改认证信息
     */
    public function editShopCert($data, $condition, $type = 0)
    {
        $info = model('shop_cert')->getInfo($condition);

        model()->startTrans();
        try {
            if (!empty($info)) {
                $cert_id = $info[ 'cert_id' ];
                $res = model('shop_cert')->update($data, $condition);
            } else {
                $res = $this->addShopCert($data);
                $cert_id = $res[ 'data' ];
            }
            if ($type == 1) {
                $this->editShop([ 'cert_id' => $cert_id ], $condition);
            }

            model("shop_cert")->commit();
            return $this->success($res);
        } catch (\Exception $e) {
            model("shop_cert")->rollback();
            return $this->error("", $e->getMessage());
        }
    }

    /**
     * 获取店铺认证信息(包含结算账户)
     * @param unknown $site_id
     */
    public function getShopCert($condition, $field = '*')
    {
        $res = model('shop_cert')->getInfo($condition, $field);
        return $this->success($res);
    }


    /**
     * 获取申请店铺数
     * @param array $condition
     */
    public function getShopCount($condition = [])
    {
        $res = model('shop')->getCount($condition);
        return $this->success($res);
    }

    /**
     * 店铺推广二维码
     * @param $site_id
     * @param string $type
     * @return array
     */
    public function qrcode($site_id, $type = "create")
    {
        $data = [
            'app_type' => "all", // all为全部
            'type' => $type, // 类型 create创建 get获取
            'data' => [
                "site_id" => $site_id
            ],
            'page' => '/otherpages/shop/index/index',
            'qrcode_path' => 'upload/qrcode/shop/',
            'qrcode_name' => "shop_qrcode_" . $site_id,
        ];

        event('Qrcode', $data);
        $app_type_list = config('app_type');

        $config = new ConfigModel();

        $path = [];

        //获取站点信息
        $h5_domain = getH5Domain();

        foreach ($app_type_list as $k => $v) {
            switch ( $k ) {
                case 'h5':
                        $path[ $k ][ 'status' ] = 1;
                        $path[ $k ][ 'url' ] = $h5_domain . $data[ 'page' ] . '?site_id=' . $site_id;
                        $path[ $k ][ 'img' ] = $data[ 'qrcode_path' ] . $data[ 'qrcode_name' ] . '_' . $k . '.png';
                    break;
                case 'weapp' :
                    $res = $config->getConfig([ [ 'site_id', '=', 0 ], [ 'app_module', '=', 'admin' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
                    if (!empty($res[ 'data' ])) {
                        if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
                            $path[ $k ][ 'status' ] = 2;
                            $path[ $k ][ 'message' ] = '未配置微信小程序';
                        } else {
                            $path[ $k ][ 'status' ] = 1;
                            $path[ $k ][ 'img' ] = $data[ 'qrcode_path' ] . $data[ 'qrcode_name' ] . '_' . $k . '.png';;
                        }

                    } else {
                        $path[ $k ][ 'status' ] = 2;
                        $path[ $k ][ 'message' ] = '未配置微信小程序';
                    }
                    break;

                case 'wechat' :
                    $res = $config->getConfig([ [ 'site_id', '=', 0 ], [ 'app_module', '=', 'admin' ], [ 'config_key', '=', 'WECHAT_CONFIG' ] ]);
                    if (!empty($res[ 'data' ])) {
                        if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
                            $path[ $k ][ 'status' ] = 2;
                            $path[ $k ][ 'message' ] = '未配置微信公众号';
                        } else {
                            $path[ $k ][ 'status' ] = 1;
                            $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
                        }
                    } else {
                        $path[ $k ][ 'status' ] = 2;
                        $path[ $k ][ 'message' ] = '未配置微信公众号';
                    }
                    break;
            }

        }

        $return = [
            'path' => $path,
        ];
        return $this->success($return);
    }

    /**
     * 添加店铺(安装时调用)
     * @param unknown $shop_data 店铺信息(注意是否自营)
     * @param unknown $user_info 用户信息
     */
    public function installShop($shop_data, $user_info)
    {
        model('shop')->startTrans();
        try {
            //添加系统站
            $site_id = model("site")->add([ 'site_type' => 'shop' ]);

            $cert_data = [ 'site_id' => $site_id ];

            //添加店铺认证信息
            $cert_id = model("shop_cert")->add($cert_data);

            $shop_data[ 'site_id' ] = $site_id;

            $shop_data[ 'expire_time' ] = 0;
            $shop_data[ "cert_id" ] = $cert_id;

            $shop_data[ 'username' ] = $user_info[ 'username' ];

            $shop_data[ 'create_time' ] = time();
            //添加店铺
            $res = model("shop")->add($shop_data);
            $cert_data[ 'site_id' ] = $site_id;

            //添加系统用户组
            $group = new Group();
            $group_data = [
                'site_id' => $site_id,
                'app_module' => 'shop',
                'group_name' => '管理员组',
                'is_system' => 1,
                'menu_array' => '',
                'create_time' => time()
            ];
            $group_id = $group->addGroup($group_data)[ 'data' ];
            // 添加店铺相册默认分组
            model("album")->add([ 'site_id' => $site_id, 'album_name' => "默认分组", 'update_time' => time(), 'is_default' => 1 ]);

            //添加用户
            $data_user = [
                'app_module' => 'shop',
                'app_group' => $shop_data[ 'group_id' ],
                'is_admin' => 1,
                'group_id' => $group_id,
                'group_name' => '管理员组',
                'site_id' => $site_id
            ];
            $user_info = array_merge($data_user, $user_info);
            model("user")->add($user_info);
            //执行事件
            event("AddShop", [ 'site_id' => $site_id ]);

            model("shop")->commit();
            return $this->success($site_id);
        } catch (\Exception $e) {
            model("shop")->rollback();
            return $this->error("", $e->getMessage());
        }
    }

    /**
     * 店铺关闭
     * @param $site_id
     */
    public function shopClose($site_id)
    {
        $res = model("shop")->update([ "shop_status" => 0 ], [ [ "site_id", "=", $site_id ] ]);
        if ($res === false)
            return $this->error();

        $close_result = event("ShopClose", [ "site_id" => $site_id ], true);
        if (!empty($close_result) && $close_result[ "code" ] < 0) {
            return $close_result;
        }
        return $this->success();
    }

    /**
     * 是否显示店铺相关功能，用于审核小程序
     * @return int
     */
    public function getDevelopment()
    {
        // 0 隐藏，1 显示
        return 1;
    }

    public function frozenShop($condition, $shop_status)
    {

        $res = model('shop')->update([ 'shop_status' => $shop_status ], $condition);

        return $this->success($res);
    }


    /**
     * 转换秒杀时间
     * @param $info
     * @return mixed
     */
    public function transformSeckillTime($info)
    {
        $info[ 'start_hour' ] = floor($info[ 'start_time' ] / 3600);
        $info[ 'start_minute' ] = floor(( $info[ 'start_time' ] % 3600 ) / 60);

        $info[ 'end_hour' ] = floor($info[ 'end_time' ] / 3600);
        $info[ 'end_minute' ] = floor(( $info[ 'end_time' ] % 3600 ) / 60);

        if ($info[ 'start_hour' ] < 10) $info[ 'start_hour' ] = '0' . $info[ 'start_hour' ];
        if ($info[ 'start_minute' ] < 10) $info[ 'start_minute' ] = '0' . $info[ 'start_minute' ];


        if ($info[ 'end_hour' ] < 10) $info[ 'end_hour' ] = '0' . $info[ 'end_hour' ];
        if ($info[ 'end_minute' ] < 10) $info[ 'end_minute' ] = '0' . $info[ 'end_minute' ];

        return $info;
    }

    //提交汇付
    public function submitHuifu($condition)
    {
        model('shop')->startTrans();

        try {
            $return_url = addon_url("pay/huifu/shopnotify");

            $info = model('shop')->getInfo($condition);

            $huifu_model = new Huifu();
            $req_seq_id = date("YmdHis");
            if ($info['cert_type']==1){
                $legal_cert_back_pic_url = root_path() .$info['contacts_card_electronic_2'];
                $legal_cert_back_pic = $huifu_model->upload('F41', $legal_cert_back_pic_url,'身份证正面.png');
                $legal_cert_back_pic_file_id = $legal_cert_back_pic['data']['file_id'];

                $legal_cert_front_pic_url = root_path() .$info['contacts_card_electronic_3'];
                $legal_cert_front_pic = $huifu_model->upload('F40',$legal_cert_front_pic_url,'身份证反面.png');
                $legal_cert_front_pic_file_id = $legal_cert_front_pic['data']['file_id'];

                $settle_card_front_pic_url = root_path() .$info['settlement_bank_img'];
                $settle_card_front_pic = $huifu_model->upload('F13',$settle_card_front_pic_url,'银行卡.png');
                $settle_card_front_pic_file_id = $settle_card_front_pic['data']['file_id'];

                $card_info = [
                    'card_name'=>$info['settlement_bank_account_name'],
                    'card_no'=>$info['settlement_bank_account_number'],
                    //'area_id'=>'310100',
                    'cert_type'=>'00',
                    'cert_no'=>$info['contacts_card_no'],
                    'cert_validity_type'=>$info['legal_cert_validity_type'],
                    'cert_begin_date'=>date('Ymd',strtotime($info['contacts_card_start_time'])),
                    'cert_end_date'=>date('Ymd',strtotime($info['contacts_card_end_time']))
                ];
                //个人店铺
                $data = [
                    'req_seq_id'=>$req_seq_id,
                    'reg_name'=>$info['site_name'],
                    'prov_id'=>$info['province'],
                    'area_id'=>$info['city'],
                    'district_id'=>$info['district'],
                    'detail_addr'=>$info['full_address'].$info['address'],
                    'contact_name'=>$info['name'],
                    'contact_mobile_no'=>$info['mobile'],
                    'contact_email'=>$info['contact_email'],
                    'return_url'=>$return_url,
                    'mcc'=>'5399',
                    'scene_type'=>'ALL',
                    'legal_cert_no'=>$info['contacts_card_no'],
                    'legal_cert_begin_date'=>$info['contacts_card_start_time'],

                    'legal_cert_end_date'=>$info['contacts_card_end_time'],
                    'legal_addr'=>$info['legal_addr'],
                    'legal_cert_back_pic'=>$legal_cert_back_pic_file_id,
                    'legal_cert_front_pic'=>$legal_cert_front_pic_file_id,
                    'settle_card_front_pic'=>$settle_card_front_pic_file_id,
                    'card_info'=>json_encode($card_info,320)
                ];

                $result = $huifu_model->personalMerchantPurchase($data);

            } else {

                $license_pic_url = root_path() .$info['business_licence_number_electronic'];
                $license_pic = $huifu_model->upload('F07', $license_pic_url,'营业执照.png');
                $license_pic_file_id = $license_pic['data']['file_id'];

                //银行卡类型,1对公,2对私,3对私非法人
                if ($info['settlement_bank_type']==1){
                    $card_type = 0;
                } elseif ($info['settlement_bank_type']==2){
                    $card_type = 1;
                } elseif ($info['settlement_bank_type']==3){
                    $card_type = 2;
                }
                $card_info = [
                    'card_name'=>$info['settlement_bank_account_name'],
                    'card_no'=>$info['settlement_bank_account_number'],
                    'cert_type'=>'00',
                    'card_type'=>$card_type,//0：对公账户 1：对私法人账户 2：对私非法人账户
                ];
                if ($card_type==0){
                    $card_info['prov_id'] = $info['bank_province'];
                    $card_info['area_id'] = $info['bank_city'];
                }
                //企业
                $data = [
                    'req_seq_id'=>$req_seq_id,
                    'reg_name'=>$info['site_name'],
                    'short_name'=>$info['site_name'],
                    'ent_type'=>0,
                    'license_pic'=>$license_pic_file_id,
                    'license_code'=>$info['business_licence_number'],
                    'license_validity_type'=>$info['license_time_type'],
                    'license_begin_date'=>$info['license_start_date'],
                    'license_end_date'=>$info['license_end_date'],
                    'reg_prov_id'=>$info['province'],
                    'reg_area_id'=>$info['city'],
                    'reg_district_id'=>$info['district'],
                    'reg_detail'=>$info['full_address'].$info['address'],
                    'legal_name'=>$info['contacts_card_name'],
                    'legal_cert_type'=>'00',
                    'legal_cert_no'=>$info['contacts_card_no'],
                    'legal_cert_validity_type'=>$info['legal_cert_validity_type'],
                    'legal_cert_begin_date'=>$info['contacts_card_start_time'],
                    'legal_cert_end_date'=>$info['contacts_card_end_time'],
                    'legal_addr'=>$info['legal_addr'],
                    'prov_id'=>$info['province'],
                    'area_id'=>$info['city'],
                    'district_id'=>$info['district'],
                    'detail_addr'=>$info['full_address'].$info['address'],
                    'contact_mobile_no'=>$info['mobile'],
                    'mcc'=>'5399',
                    'scene_type'=>'ALL',
                    'receipt_name'=>$info['site_name'],
                    'contact_email'=>$info['contact_email'],
                    'busi_type'=>$info['busi_type'],
                    'return_url'=>$return_url,
                    'card_info'=>json_encode($card_info,320)
                ];
                //dump($data);die;
                $result = $huifu_model->businessMerchantPurchase($data);
            }

            if ($result[ "code" ] < 0)
                return $result;

            $update_data = [
                'req_seq_id'=>$req_seq_id,
                'huifu_audit_status'=>1,
                'huifu_id'=>$result['data']['huifu_id'],
                'huifu_apply_no'=>$result['data']['apply_no'] ?? '',
                'huifu_resp_desc'=>$result['data']['resp_desc'] ?? '',
                'huifu_token_no'=>$result['data']['token_no'] ?? '',
            ];

            $res = model('shop')->update($update_data,$condition);

            model('shop')->commit();

            return $this->success($res);

        }  catch (\Exception $e) {
            model('shop')->rollback();
            return $this->error('', $e->getMessage());
        }

    }

}